//window.auOrderStatus = 0;
var auOrderStatus = 0;

$(function(){
    $("#edit").attr("disabled",false);
});

//发货
function send(auId){
// alert("aa-"+auId+"----");
	$.post("updateShopAuOrderStatus",{
		auId : auId,
        auOrderStatus : 1
	},function(data){
		if(data.code == 200){
			layer.msg(data.msg, {icon : 1,time : 1500});
			setTimeout(function(){
				$("#table").bootstrapTable('refresh');
			},1500);
		}else{
			layer.msg(data.msg, {icon : 2,time : 1500});
		}
	},"json");
}



//修改 查看
$("#edit").click(function() {
	var ids = getSelections(); 
	var orderList = getSelectionss(); 
	if (ids.length == 1) {
		// 根据id 查询信息 
		$("input[name=auId]").val(orderList[0].au_id);
		$("input[name=reName]").val(orderList[0].re_name);
		$("input[name=rePhone]").val(orderList[0].re_phone);
		$("input[name=reAdd]").val(orderList[0].re_add);
		$("input[name=reId]").val(orderList[0].re_id);
	
		$('#modal-edit').modal('toggle');
	}else if(ids.length == 0){
		layer.msg("未选择数据");
	}else{
		layer.msg("请勿勾选多个");
	}
});

//确认修改
$("#editBtn").click(function(){
	
	var auId = $("#auId").val();
	var reId = $("#reId").val();
	var reName = $("#reName").val();
	var rePhone = $("#rePhone").val();
	var reAdd = $("#reAdd").val();
	
	$.post("updateReceiveGood",
		{auId : auId,reId : reId,reName : reName,rePhone : rePhone,reAdd : reAdd},
		function(data){
			if(data.code == 200){
				layer.msg("修改成功", {icon : 1,time : 1500});
			}else{
				layer.msg("修改失败", {icon : 2,time : 1500});
			}
		},"json");
});


//删除 deleteBtn
$("#deleteBtn").click(function(){
	var ids = getSelections(); 
	if(ids.length == 0){
		layer.msg("未选择数据");
	}else{
		layer.msg("删除成功", {icon : 1,time : 1500,});
	}
});


    $("#ns").click(function () {
        auOrderStatus = 0;
        $("#table").bootstrapTable('refresh');
        //设置编辑按钮可编辑
 		$("#edit").attr("disabled",false);
    });

    $("#nr").click(function () {
       auOrderStatus = 1;
        $("#table").bootstrapTable('refresh');

        $("#edit").attr("disabled",true);
    });

    $("#af").click(function () {
        auOrderStatus = 2;
        $("#table").bootstrapTable('refresh');
        $("#edit").attr("disabled",true);
    });

    $("#shopTypeId").change(function () {
        $("#table").bootstrapTable('refresh');
    });


    function queryParams(p) {
        var userId = $("#userId").val();
        p.userId = userId;
        p.shopTypeId = $('#shopTypeId option:selected').val();
        p.auOrderStatus = auOrderStatus;
        return p;
    }


function getSelections() {
	return $.map($('#table').bootstrapTable('getSelections'),function(row) {
		return row.au_id;
	});
}

function getSelectionss() {
	return $.map($('#table').bootstrapTable('getSelections'),function(row) {
		return row;
	});
}

function price(value, row, index) {
    var shopPrice = row.shop_price;
    var increPrice = row.incre_tall_price;
    if(increPrice == null || increPrice == "undefined" || increPrice == 0){
        increPrice = 0;
	}
    var tall = shopPrice + increPrice;
    if (tall != null) {
        return [
            "<span>"+tall+"</span>"
        ].join('');
    }
}

function status(value, row, index) {
	var ostatus = row.au_order_status;
    var auId = row.au_id;
	if(ostatus == 0){
		return [
			"<span style='color: #1818f5;'>已付款，代发货 &nbsp;<button onclick='send("+auId+")' style='color: #000000;'>发货</button></span>"
		].join('');	
	}

	if(ostatus == 1){
		return [
			"<span style='color: #6d9eeb;'>已发货，代收货</span>"
		].join('');	
	}
	if(ostatus == 2){
		return [
			"<span style='color: #6d9eeb;'>已完成</span>"
		].join('');	
	}
}
